package com.qpx.redis.controller;

import com.qpx.redis.model.User;
import com.qpx.redis.service.PeopleNearbyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private PeopleNearbyService nearbyService;

    @RequestMapping("hello")
    public String hello() {
        return "hello";
    }

    /**
     * 保存用户信息
     *
     * @param user
     * @return
     */
    @RequestMapping(value = "saveInfo", method = RequestMethod.POST)
    public boolean saveInfo(@RequestBody User user) {
        return nearbyService.save(user);
    }

    /**
     * 查询指定距离（km）范围内的用户
     *
     * @param distance 距离
     * @param userLng 经度
     * @param userLat 纬度
     * @return
     */
    @RequestMapping("/searchNearby")
    public List<User> searchNearby(@RequestParam("distance") double distance,
                                   @RequestParam("userLng") double userLng,
                                   @RequestParam("userLat") double userLat) {
        return nearbyService.nearBySearch(distance, userLng, userLat);
    }

    /**
     * 查询指定距离（km）范围内的用户
     *
     * @param distance
     * @param name
     * @return
     */
    @RequestMapping("/searchNearbyName")
    public List<User> searchNearbyName(@RequestParam("distance") double distance,
                                       @RequestParam("name") String name) {
        return nearbyService.searchNearbyName(distance, name);
    }
}
